
#import "HTTPClient.h"


@interface HTTPClient ()

@end


@implementation HTTPClient

+ (instancetype)sharedHttpClient {

    static HTTPClient *_instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        
        _instance = [[HTTPClient alloc] init];
        
        _instance.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", nil];
    });
    return _instance;
}


- (void)request:(HTTPMethod)method URLString:(NSString *)URLString parameters:(id)parameters finished:(void (^)(id, NSError *))finished {
    
        if (method == GET) {
            
            
            [self GET:URLString parameters:parameters progress:^(NSProgress * _Nonnull downloadProgress) {
                NSLog(@"%@",downloadProgress);
            } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                finished(responseObject,nil);
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                finished(nil,error);
            }];
    
        } else {
            
            [self POST:URLString parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {
                NSLog(@"%@",uploadProgress);
            } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                finished(responseObject,nil);
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                
                finished(nil,error);
            }];
        }
}


@end
